<template>
   <Head>
      <Title>{{ SystemData.SystemInfo?.systemName }}-{{ cnyzs.COMMON_NAME }}</Title>
      <Meta name="keywords" :content="SystemData.SystemInfo?.systemName" />
      <Meta name="description" :content="SystemData.SystemInfo?.systemName" />
   </Head>
   <component class="component GradientAnimation" :is="componentsVue.get(SystemData.SystemInfo.systemType)"
      :SystemData="SystemData" />
   <ManagementVue v-if="managementShow" :SystemData="SystemData" />
   <AnnouncementVue :SystemData="SystemData" />
   <ErrorVue v-if="!SystemData.SystemInfo._id" />
</template>
<script lang="ts" setup >
import { storeToRefs } from 'pinia';
import ManagementVue from "./Management/index.vue"
import AnnouncementVue from "./Announcement/index.vue"
import ErrorVue from "./404.vue"
const { cnyzs, systemType } = storeToRefs(cnyzsCommonpinia())
const { managementShow } = storeToRefs(cnyzsCommonpinia())
const { params: { SystemType } } = useRoute() as string | any
const componentsVue = new Map<string, any>()
const componentsArr = ['ForumSystem']
const componentsMap = [
   { components: defineAsyncComponent(() => import('@/pages/System/Forum/index.vue')) }, // 社区类型
]
componentsMap.map((v: any, index: number) => componentsVue.set(componentsArr[index], v.components))

// 系统数据储存
const SystemData = ref({
   SystemInfo: {} as any,   // 必须数据：统一接口返回，系统信息
   SystemConfig: {},        // 必须数据：统一接口返回，系统配置
   SystemAnnounceList: [],  // 必须数据：统一接口返回，系统公告
   SystemUserInfo: {},      // 必须数据：统一接口返回，系统用户信息 (非主程序用户信息，系统也有一个独立用户信息，和主程序信息混合使用)
   SystemUserList: [],      // 系统用户列表
   SystemClassifyList: [],  // 系统分类列表
   SystemPostsList: [],     // 系统帖子列表 (分页获取)
   SystemPostsTopList: [],     // 系统置顶帖子列表
})

// 获取系统必要数据：系统信息 系统配置 系统公告 系统用户信息 
const Get_system_info_config_userinfo_announce = async () => {
   const res: any = await cnyzsRequest('/api/cnyzs-system/queryAllsysteminfo', { method: 'POST', data: { systemSign: SystemType || systemType.value } })
   const data = res.data
   SystemData.value.SystemInfo = data.SystemInfo
   SystemData.value.SystemConfig = data.SystemConfig
   SystemData.value.SystemAnnounceList = data.SystemAnnounceList
   SystemData.value.SystemUserInfo = data.SystemUserInfo
   SystemData.value.SystemClassifyList = data.SystemClassifyList
}
await Get_system_info_config_userinfo_announce()
// 替换系统色调
onMounted(() => {
   if (SystemData.value.SystemInfo.systemColor) {
      document.body.style.setProperty('--aoir-color-primary', SystemData.value.SystemInfo.systemColor);
   } else {
      document.body.style.setProperty('--aoir-color-primary', cnyzs.value.COMMON_THEMECOLOR);
   }
})

</script>
<style lang="scss" scoped>
.component {
   width: var(--aoir-m-width);
   min-height: 100vh;
   margin: 0 auto;
}
</style>